<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <article></article>
    <script>
        // 1.批量替换敏感词
        var origin = 'asHHdMMadHHsNNfHHdNNaMMgHHfas'
        var a = ['HH', 'MM', 'NN']
        var str = origin
        for (var i = 0; i < a.length; i++) {
            str = str.split(a[i]).join("※")
        }
        console.log(str);

        // 2.解析字符串
        var origin = 'name=Jack&age=18&gender=男'
        var arr = origin.split("&")
        var obj = {}
        for (var i = 0; i < arr.length; i++) {
            var tmp = arr[i].indexOf("=")
            obj[arr[i].slice(0, tmp)] = arr[i].slice(tmp + 1)
        }
        console.log(obj);

        //3. [
        //     {pinpai: "华为", xinghao: "mate40", price: 5499},
        //     {pinpai: "华为", xinghao: "p30", price: 2099},
        //     {pinpai: "苹果", xinghao: "iphone13", price: 5999},
        //     {pinpai: "苹果", xinghao: "iphone12", price: 2999},
        //     {pinpai: "vivo", xinghao: "x80", price: 3299},
        //     {pinpai: "oppo", xinghao: "find3pro", price: 5999},
        //     {pinpai: "8848", xinghao: "金镶钻x1", price: 19888},
        // ]
        // 将这个数组中的所有价格低于5000 大于 2000的过滤出来 放入一个新的数组
        var arr2 = [
            { pinpai: "华为", xinghao: "mate40", price: 5499 },
            { pinpai: "华为", xinghao: "p30", price: 2099 },
            { pinpai: "苹果", xinghao: "iphone13", price: 5999 },
            { pinpai: "苹果", xinghao: "iphone12", price: 2999 },
            { pinpai: "vivo", xinghao: "x80", price: 3299 },
            { pinpai: "oppo", xinghao: "find3pro", price: 5999 },
            { pinpai: "8848", xinghao: "金镶钻x1", price: 19888 },
        ]
        var newarr = []
        // 3-1直接复制方案
        for (var i = 0; i < arr2.length; i++) {
            var tmpObj = arr2[i]
            if (tmpObj["price"] > 2000 && tmpObj["price"] < 5000) {
                newarr.push(tmpObj)
            }
            
        }
        console.log(newarr);
        

        // 3-2深复制方案
        var newarr2 = []
        for (var i = 0; i < arr2.length; i++) {
            var tmpObj = arr2[i]
            if (tmpObj["price"] > 2000 && tmpObj["price"] < 5000) {
                newarr2[newarr2.length] = deepCopy(tmpObj)
            }
        }      
        arr2[1].price = 2222
        console.log(newarr2);

        //深复制代码
        function deepCopy(target) {
            var obj1 = {}
            for (var i in target) {
                // 判定这条属性是值类型的值还是引用类型的值
                if (typeof target[i] === 'object' && target[i] != null) {
                    obj1[i] = deepCopy(target[i]);
                } else {
                    // 值类型
                    obj1[i] = target[i];
                }
            }
            return obj1;
        }
    </script>
</body>

</html>